cmake_minimum_required(VERSION 3.5)

project(dal_msg)

add_subdirectory(test)

# fastdds
file(GLOB DAL_TYPESUPPORT_FASTDDS_SRCS
    "${PROJECT_SOURCE_DIR}/src/dcutils/src/*.c"
    "${PROJECT_SOURCE_DIR}/src/dcpputils/src/*.cpp"
    "${PROJECT_SOURCE_DIR}/src/dalidl/dalidl_runtime_c/src/*.c"
    "${PROJECT_SOURCE_DIR}/src/dalidl/dalidl_runtime_c/src/*.cpp"
    "${PROJECT_SOURCE_DIR}/src/dalidl/dalidl_typesupport_introspection_cpp/src/*.cpp"
    "${PROJECT_SOURCE_DIR}/src/dalidl/dalidl_typesupport_introspection_c/src/*.c"
    "${PROJECT_SOURCE_DIR}/src/dalidl_typesupport/dalidl_typesupport_cpp/src/*.c"
    "${PROJECT_SOURCE_DIR}/src/dalidl_typesupport/dalidl_typesupport_cpp/src/*.cpp"
    "${PROJECT_SOURCE_DIR}/src/dalidl_typesupport_fastrtps/dalidl_typesupport_fastrtps_cpp/src/*.cpp"
    "${PROJECT_SOURCE_DIR}/src/dal_fastrtps/dal_fastrtps_cpp/src/*.cpp"
    "${PROJECT_SOURCE_DIR}/src/dal_fastrtps/dal_fastrtps_cpp_shared/src/*.cpp"
)

add_library(dal_typesupport_fastdds_depends SHARED ${DAL_TYPESUPPORT_FASTDDS_SRCS})

target_include_directories(dal_typesupport_fastdds_depends PUBLIC
    include/dcutils
    include/dcpputils
    include/dalidl
    include/dalidl/dalidl_runtime_c
    include/dalidl/dalidl_runtime_cpp
    include/dalidl_typesupport
    include/dalidl_typesupport_interface
    include/dalidl_typesupport_fastrtps
    include/dalidl_typesupport_introspection
    include/dal
    include/dal_fastrtps
    include/dal_fastrtps/dal_fastrtps_cpp)

# cyclonedds
file(GLOB DAL_TYPESUPPORT_CYCLONEDDS_SRCS
    "${PROJECT_SOURCE_DIR}/src/dcutils/src/*.c"
    "${PROJECT_SOURCE_DIR}/src/dcpputils/src/*.cpp"
    "${PROJECT_SOURCE_DIR}/src/dalidl/dalidl_runtime_c/src/*.c"
    "${PROJECT_SOURCE_DIR}/src/dalidl/dalidl_typesupport_introspection_c/src/*.c"
    "${PROJECT_SOURCE_DIR}/src/dalidl/dalidl_typesupport_introspection_cpp/src/*.cpp"
    "${PROJECT_SOURCE_DIR}/src/dalidl_typesupport/dalidl_typesupport_cpp/src/*.cpp"
    "${PROJECT_SOURCE_DIR}/src/dal_cyclonedds/dal_cyclonedds_cpp/src/*.cpp"
)

add_library(dal_typesupport_cyclonedds_depends SHARED ${DAL_TYPESUPPORT_CYCLONEDDS_SRCS})

target_include_directories(dal_typesupport_cyclonedds_depends PUBLIC
    include/dcutils
    include/dcpputils
    include/dalidl
    include/dalidl/dalidl_runtime_c
    include/dalidl/dalidl_runtime_cpp
    include/dalidl_typesupport
    include/dalidl_typesupport_interface
    include/dalidl_typesupport_introspection
    include/dal
    include/dal_cyclonedds/dal_cyclonedds_cpp
)

# rticonnextdds
if(${BUILD_RTIDDS})
if(CMAKE_EXTRA_SYSTEM MATCHES QNX)
    add_definitions(-DRTI_QNX)
else()
    add_definitions(-DRTI_UNIX)
endif()

file(GLOB DAL_TYPESUPPORT_RTICONNEXTDDS_SRCS
    "${PROJECT_SOURCE_DIR}/src/dcutils/src/*.c"
    "${PROJECT_SOURCE_DIR}/src/dcpputils/src/*.cpp"
    "${PROJECT_SOURCE_DIR}/src/dalidl/dalidl_runtime_c/src/*.c"
    "${PROJECT_SOURCE_DIR}/src/dalidl/dalidl_typesupport_introspection_c/src/*.c"
    "${PROJECT_SOURCE_DIR}/src/dalidl/dalidl_typesupport_introspection_cpp/src/*.cpp"
    "${PROJECT_SOURCE_DIR}/src/dalidl_typesupport/dalidl_typesupport_cpp/src/*.cpp"
    "${PROJECT_SOURCE_DIR}/src/dalidl_typesupport_fastrtps/*/src/*.cpp"
    "${PROJECT_SOURCE_DIR}/src/dal/src/*.c"
    "${PROJECT_SOURCE_DIR}/src/dal_dds_common/src/*.cpp"
    "${PROJECT_SOURCE_DIR}/src/dal_dds_common/src/msg/detail/*.c"
    "${PROJECT_SOURCE_DIR}/src/dal_dds_common/src/msg/detail/*.cpp"
    "${PROJECT_SOURCE_DIR}/src/dal_connextdds/dal_connextdds_common/src/*/*.cpp"
)

add_library(dal_typesupport_rticonnextdds_depends SHARED ${DAL_TYPESUPPORT_RTICONNEXTDDS_SRCS})

target_include_directories(dal_typesupport_rticonnextdds_depends PUBLIC
    $ENV{NDDSHOME}/include
    $ENV{NDDSHOME}/include/ndds
    include/dcutils
    include/dcpputils
    include/dalidl
    include/dalidl/dalidl_runtime_c
    include/dalidl/dalidl_runtime_cpp
    include/dalidl_typesupport
    include/dalidl_typesupport_interface
    include/dalidl_typesupport_fastrtps
    include/dalidl_typesupport_introspection
    include/dal
    include/dal_dds_common
    include/dal_connextdds/dal_connextdds_common
)

target_link_libraries(dal_typesupport_rticonnextdds_depends
    nddscore
    nddsc
    nddscpp
    dl)
endif()

if(${BUILD_RTIDDS})
install(TARGETS dal_typesupport_fastdds_depends dal_typesupport_cyclonedds_depends dal_typesupport_rticonnextdds_depends
        LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
else()
install(TARGETS dal_typesupport_fastdds_depends dal_typesupport_cyclonedds_depends
        LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()

install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/dalidl/dalidl_runtime_c/dal_msg
        DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/dalidl/dalidl_runtime_cpp/dal_msg
        DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

